package model;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class SearchFile {
	private String path;
	private JFileChooser fileChooser;
	private JLabel pwd;
	private JLabel name;
	
	public SearchFile(JFrame frame) {
		pwd = new JLabel();
		name = new JLabel();
		fileChooser = new JFileChooser(".");
    }
	
	public String ChooseFile(ActionEvent e) {
		Component parent = (Component)e.getSource();
		
		int status = fileChooser.showOpenDialog(parent);
		if (status == JFileChooser.APPROVE_OPTION) {
		    File selectedFile = fileChooser.getSelectedFile();
		    name.setText(selectedFile.getName());
		    path = name.getText();
		    
		    return path;
		} 
		else{
			pwd.setText(" ");
		    name.setText(" ");
		    
		    return "";
		}
	}
}
